package com.press.controllers.admin;

import com.alibaba.fastjson.JSONObject;
import com.press.bean.ContentBean;
import com.press.services.PanelService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * by cherry   面板
 * Created by Lenovo on 2016/10/10.
 */
@Controller
@RequestMapping("/Panel")
public class PanelController {
    @Resource(name="panelService")
    private PanelService panelService;
    private static Logger log = Logger.getLogger(PanelController.class);

    /**
     * 面板展示controller
     * @param request
     * @param response
     */
    @RequestMapping("/ShowPressPanel")
    public void ShowPressPanel(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("utf-8");//解决从后台到前台出现的中文字符乱码的显现
        int contentnum=panelService.getContentCount();
        int commentnum=panelService.getCommentCount();
        int contentlugganum=panelService.getContentLaggCount();
        int commentluggagenum=panelService.getCommentLaggNUM();
        List<ContentBean> list=panelService.getFRecentContentMess();
        log.info("##################"+list.get(0).getContent_title());

        log.info("PanelController测试-----"+list.size()+"-----"+list.get(0).getContent_title());

        log.info("PanelController------文章数量"+contentnum+"----评论数量"+commentnum+"----文章垃圾箱"+contentlugganum);
        JSONObject json=new JSONObject();
        json.put("commentluggagenum",commentluggagenum);
        json.put("contentnum",contentnum);
        json.put("commentnum",commentnum);
        json.put("contentlugganum",contentlugganum);
        json.put("contentlist",list);
        response.getWriter().print(json.toJSONString());
    }
    public PanelService getPanelService() {
        return panelService;
    }

    public void setPanelService(PanelService panelService) {
        this.panelService = panelService;
    }
}
